package com.example.site.service.impl;

import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.site.entity.Config;
import com.example.site.service.ConfigService;
import com.example.site.mapper.ConfigMapper;
import com.example.site.vo.ConfigVo;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author haoka
 * @description 针对表【hotel_config】的数据库操作Service实现
 * @createDate 2023-04-11 22:27:19
 */
@Service
public class ConfigServiceImpl extends ServiceImpl<ConfigMapper, Config>
        implements ConfigService {
    public SaResult get() {
        QueryWrapper<Config> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", "PHONE");
        Config phoneConfig = this.getOne(queryWrapper);


        ConfigVo configVo = new ConfigVo(phoneConfig.getValue());

        return SaResult.data(configVo);
    }

    public SaResult set(Map<String, String> data) {
        String phone = data.get("phone");


        if (StringUtils.isNotBlank(phone)) {
            Config config = new Config();
            config.setName("PHONE");
            config.setValue(phone);
            QueryWrapper<Config> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("name", "PHONE");
            this.update(config, queryWrapper);
        }

        return SaResult.ok();
    }
}




